Skip to content

Revise README for FocalPointPicker component to use object-position#77722

Open
andreawetzel wants to merge 1 commit intoWordPress:trunkfrom
andreawetzel:patch-5
Open

Revise README for FocalPointPicker component to use object-position#77722
andreawetzel wants to merge 1 commit intoWordPress:trunkfrom
andreawetzel:patch-5

Conversation

@andreawetzel
Copy link
Copy Markdown
Contributor

  • Update the focal point picker's README to clarify the component's purpose both for background images and aspect ratio cropped images.
  • Update example code to use object-position

What?

The Focal Point Picker's use has expanded beyond background images and the CSS example from this README is no longer in use on core blocks such as the cover block.

Updated the focal point picker's README to clarify the component's purpose both for background images and aspect ratio cropped images.  Update example code to use `object-position`
@andreawetzel andreawetzel requested review from a team and ajitbohra as code owners April 27, 2026 20:03
@github-actions
Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: andreawetzel <awetz583@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions github-actions Bot added the [Package] Components /packages/components label Apr 27, 2026
@t-hamano t-hamano added the [Type] Developer Documentation Documentation for developers label Apr 28, 2026
Copy link
Copy Markdown
Contributor

@ciampo ciampo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @andreawetzel for working on this.

the CSS example from this README is no longer in use on core blocks such as the cover block.

It seems like the above sentence is not accurate: the Cover block uses both, depending on the rendered element:

  • objectPosition when the media is an <img>/<video> element;
  • backgroundPosition when the media is rendered as a <div> with background-image (example).

We should consider rewording the README's first paragraph so it doesn't read like object-position replaces background-position. Both remain valid targets, and the choice depends on whether the consumer renders the media via CSS background or via an <img>/<video> element. A short note like:

The output value can be applied to either CSS `background-position` (for elements with `background-image`) or `object-position` (for `<img>` / `<video>` elements rendered with `object-fit: cover`).

…keeps both use cases visible.

Optionally, a second example showing the background-image path would map cleanly onto how Cover renders today.

onChange={ setFocalPoint }
/>
<div style={ style } />
<img src={ url } style={ style } />
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the current example snippet will work as expected, we need to set object-fit and also ideally a target ratio (see https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/object-position)

const style = {
	width: '100%',
	aspectRatio: '16 / 9',
	objectFit: 'cover',
	objectPosition: `${ focalPoint.x * 100 }% ${ focalPoint.y * 100 }%`,
};

return (
	<>
		<FocalPointPicker
			url={ url }
			value={ focalPoint }
			onDragStart={ setFocalPoint }
			onDrag={ setFocalPoint }
			onChange={ setFocalPoint }
		/>
		<img src={ url } alt="" style={ style } />
	</>
);

Comment on lines 5 to +6
- Example focal point picker value: `{ x: 0.5, y: 0.1 }`
- Corresponding CSS: `background-position: 50% 10%;`
- Corresponding CSS: `object-position: 50% 10%`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add trailing semi-columns for both bullet points.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever changes we end up making to the README, we should always keep them in sync with the JSDoc in index.tsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Components /packages/components [Type] Developer Documentation Documentation for developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants